<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="楼座名称" prop="termname">

         <el-select v-model="queryParams.termname" placeholder="楼座名称" clearable>
         <el-option
            v-for="term in terminfoList"
            :key="term.termid"
            :label="term.termname"
            :value="term.termname"
            @change="handleQuery"
          />
        </el-select>
       
      </el-form-item>
     
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['house_sale:terminfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['house_sale:terminfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['house_sale:terminfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['house_sale:terminfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="terminfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="楼栋编号" align="center" prop="termid" />
      <el-table-column label="楼座名称" align="center" prop="termname" />
      <el-table-column label="楼座代码" align="center" prop="termcode" />
      <el-table-column label="业态类型" align="center" prop="termtype" />
      <el-table-column label="项目名称" align="center" prop="projectname" />
      <el-table-column label="小区名称" align="center" prop="gardenname" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['house_sale:terminfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['house_sale:terminfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改楼栋资料对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px" :inline="true">

        <el-form-item label="小区名称" prop="projectid">

          <el-select v-model="form.projectid"  placeholder="请选择小区">
                 <el-option
                  v-for="item in projectList"
                  :key="item.projectid"
                  :label="item.projectname"
                  :value="item.projectid"
                  :disabled="false"
                ></el-option> 
            </el-select>  
        </el-form-item>
        <el-form-item label="楼座名称" prop="termname">
          <el-input v-model="form.termname" placeholder="请输入楼座名称" />
        </el-form-item>
        <el-form-item label="楼座代码" prop="termcode">
          <el-input v-model="form.termcode" placeholder="请输入楼座代码,唯一" />
        </el-form-item>
         <el-form-item label="业态类型" prop="termtype">
            <el-select v-model="form.termtype"  placeholder="请选择业态类型" width="100px">
                 <el-option
                  v-for="item in termtypeinfoList"
                  :key="item.termtypeid"
                  :label="item.termtypename"
                  :value="item.termtypename"
                  :disabled="false"
                ></el-option> 
            </el-select>  
          <!-- <el-input v-model="form.termtype" placeholder="请输入业态类型" /> -->
        </el-form-item>
        <el-form-item label="大产权编号" prop="prid">
          <el-input v-model="form.prid" placeholder="请输入大产权编号" />
        </el-form-item>
        <el-form-item label="大产权应完成时间" prop="prplantime">
          <el-date-picker clearable
            v-model="form.prplantime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择大产权应完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="大产权完成时间" prop="prfacttime">
          <el-date-picker clearable
            v-model="form.prfacttime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择大产权完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报批楼号" prop="auditno">
          <el-input v-model="form.auditno" placeholder="请输入报批楼号" />
        </el-form-item>
        <el-form-item label="合同楼栋号" prop="contractno">
          <el-input v-model="form.contractno" placeholder="请输入合同楼栋号" />
        </el-form-item>
        <el-form-item label="销售面积" prop="salearea">
          <el-input v-model="form.salearea" placeholder="请输入销售面积" />
        </el-form-item>
        <el-form-item label="使用面积" prop="usearea">
          <el-input v-model="form.usearea" placeholder="请输入使用面积" />
        </el-form-item>
        <el-form-item label="绿化面积" prop="viewarea">
          <el-input v-model="form.viewarea" placeholder="请输入绿化面积" />
        </el-form-item>
        <el-form-item label="开工时间" prop="starttime">
          <el-date-picker clearable
            v-model="form.starttime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择开工时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="竣工时间" prop="endtime">
          <el-date-picker clearable
            v-model="form.endtime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择竣工时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="开盘时间" prop="saletime">
          <el-date-picker clearable
            v-model="form.saletime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择开盘时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="入住时间" prop="livetime">
          <el-date-picker clearable
            v-model="form.livetime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择入住时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="房产总数" prop="hoursecount">
          <el-input v-model="form.hoursecount" placeholder="请输入房产总数" />
        </el-form-item>
        <el-form-item label="期望售价" prop="saleprice">
          <el-input v-model="form.saleprice" placeholder="请输入期望售价" />
        </el-form-item>
        <el-form-item label="是否可售" prop="ispaid">
           <el-select v-model="form.ispaid" width:100px>
                <el-option v-for="is in ispaidlist" :label="is.name" :value="is.name" :key="is.id"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="层高(m)" prop="hourseheight">
          <el-input v-model="form.hourseheight" placeholder="请输入层高(m)" />
        </el-form-item>
        <el-form-item label="层数" prop="floorcount">
          <el-input v-model="form.floorcount" placeholder="请输入层数" />
        </el-form-item>
        <el-form-item label="楼高(m) " prop="buildheight">
          <el-input v-model="form.buildheight" placeholder="请输入楼高(m) " />
        </el-form-item>
        <el-form-item label="每层套数" prop="percount">
          <el-input v-model="form.percount" placeholder="请输入每层套数" />
        </el-form-item>
        <el-form-item label="开发商" prop="developer">
          <el-input v-model="form.developer" placeholder="请输入开发商" />
        </el-form-item>
        <el-form-item label="工程建筑规划区号" prop="buildadultno">
          <el-input v-model="form.buildadultno" placeholder="请输入工程建筑规划区号" />
        </el-form-item>
        <el-form-item label="描述" prop="description">
          <el-input v-model="form.description" type="textarea" placeholder="请输入内容" style="width:250px" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTerminfo, getProject, getTerminfo, delTerminfo, addTerminfo, updateTerminfo } from "@/api/house_sale/terminfo";
import {  getOthers } from "@/api/house_sale/houseinfo";
export default {
  name: "Terminfo",
  dicts: ['sys_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 楼栋资料表格数据
      terminfoList: [],
      projectList:[],
      termtypeinfoList: [],
      ispaidlist:[
        {id:1,name:"是"},
        {id:2,name:"否"}
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        termname: null,
      
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        projectid: [
          { required: true, message: "项目编号不能为空", trigger: "blur" }
        ],
        termname: [
          { required: true, message: "楼座名称不能为空", trigger: "blur" }
        ],
        termcode: [
          { required: true, message: "楼座代码,唯一不能为空", trigger: "blur" }
        ],
        termtype: [
          { required: true, message: "业态类型不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询楼栋资料列表 */
    getList() {
      this.loading = true;
      listTerminfo(this.queryParams).then(response => {
        this.terminfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
        getOthers().then(response => {
        this.termtypeinfoList = response.termtypeinfoList;
       
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        termid: null,
        projectid: null,
        termname: null,
        termcode: null,
        termtype: this.termtypeinfoList[0].termtypename,
        prid: null,
        prplantime: null,
        prfacttime: null,
        auditno: null,
        contractno: null,
        salearea: null,
        usearea: null,
        viewarea: null,
        starttime: null,
        endtime: null,
        saletime: null,
        livetime: null,
        hoursecount: null,
        saleprice: null,
        ispaid: '是',
        hourseheight: null,
        floorcount: null,
        buildheight: null,
        percount: null,
        developer: null,
        buildadultno: null,
        buildtype: null,
        description: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.termid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
        getOthers().then(response => {
        this.termtypeinfoList = response.termtypeinfoList;
      });
        getProject().then(response => {
        this.projectList = response.projectList;
        this.open = true;
        this.title = "添加楼栋资料";
      });
    
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const termid = row.termid || this.ids
      getTerminfo(termid).then(response => {
        this.projectList = response.projectList;
        this.form = response.terminfo;
        this.open = true;
        this.title = "修改楼栋资料";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.termid != null) {
            updateTerminfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTerminfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const termids = row.termid || this.ids;
      this.$modal.confirm('是否确认删除楼栋资料编号为"' + termids + '"的数据项？').then(function() {
        return delTerminfo(termids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('house_sale/terminfo/export', {
        ...this.queryParams
      }, `terminfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
